home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sermgrax / frmconfi.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-08  |  12.2 KB  |  365 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
  3. Begin VB.Form frmConfigure 
  4.    BorderStyle     =   3  'Fixed Dialog
  5.    Caption         =   "Configure Service"
  6.    ClientHeight    =   4050
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   3585
  10.    Icon            =   "frmConfigure.frx":0000
  11.    LinkTopic       =   "Form1"
  12.    MaxButton       =   0   'False
  13.    MinButton       =   0   'False
  14.    ScaleHeight     =   4050
  15.    ScaleWidth      =   3585
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   1  'CenterOwner
  18.    Begin MSComctlLib.ListView listDependencies 
  19.       Height          =   975
  20.       Left            =   1320
  21.       TabIndex        =   11
  22.       Top             =   2520
  23.       Width           =   2175
  24.       _ExtentX        =   3836
  25.       _ExtentY        =   1720
  26.       View            =   3
  27.       LabelEdit       =   1
  28.       Sorted          =   -1  'True
  29.       LabelWrap       =   -1  'True
  30.       HideSelection   =   -1  'True
  31.       HideColumnHeaders=   -1  'True
  32.       Checkboxes      =   -1  'True
  33.       _Version        =   393217
  34.       ForeColor       =   -2147483640
  35.       BackColor       =   -2147483643
  36.       BorderStyle     =   1
  37.       Appearance      =   1
  38.       NumItems        =   1
  39.       BeginProperty ColumnHeader(1) {BDD1F052-858B-11D1-B16A-00C0F0283628} 
  40.          Object.Width           =   3087
  41.       EndProperty
  42.    End
  43.    Begin VB.CommandButton cmdOK 
  44.       Caption         =   "OK"
  45.       Default         =   -1  'True
  46.       Height          =   375
  47.       Left            =   1200
  48.       TabIndex        =   12
  49.       Top             =   3600
  50.       Width           =   1095
  51.    End
  52.    Begin VB.CommandButton cmdCancel 
  53.       Cancel          =   -1  'True
  54.       Caption         =   "Cancel"
  55.       Height          =   375
  56.       Left            =   2400
  57.       TabIndex        =   13
  58.       Top             =   3600
  59.       Width           =   1095
  60.    End
  61.    Begin VB.ComboBox cboErrorControl 
  62.       Height          =   315
  63.       ItemData        =   "frmConfigure.frx":000C
  64.       Left            =   1320
  65.       List            =   "frmConfigure.frx":001C
  66.       Style           =   2  'Dropdown List
  67.       TabIndex        =   9
  68.       Top             =   2040
  69.       Width           =   2175
  70.    End
  71.    Begin VB.ComboBox cboServiceType 
  72.       Height          =   315
  73.       ItemData        =   "frmConfigure.frx":0042
  74.       Left            =   1320
  75.       List            =   "frmConfigure.frx":0052
  76.       Style           =   2  'Dropdown List
  77.       TabIndex        =   7
  78.       Top             =   1560
  79.       Width           =   2175
  80.    End
  81.    Begin VB.TextBox txtFileName 
  82.       Height          =   285
  83.       Left            =   1320
  84.       TabIndex        =   5
  85.       Top             =   1080
  86.       Width           =   2175
  87.    End
  88.    Begin VB.TextBox txtDisplayName 
  89.       Height          =   285
  90.       Left            =   1320
  91.       TabIndex        =   3
  92.       Top             =   600
  93.       Width           =   2175
  94.    End
  95.    Begin VB.TextBox txtServiceName 
  96.       Height          =   285
  97.       Left            =   1320
  98.       TabIndex        =   1
  99.       Top             =   120
  100.       Width           =   2175
  101.    End
  102.    Begin VB.Label Label6 
  103.       Caption         =   "De&pendencies:"
  104.       Height          =   255
  105.       Left            =   120
  106.       TabIndex        =   10
  107.       Top             =   2520
  108.       Width           =   1215
  109.    End
  110.    Begin VB.Label Label5 
  111.       Caption         =   "Error &Control:"
  112.       Height          =   255
  113.       Left            =   120
  114.       TabIndex        =   8
  115.       Top             =   2040
  116.       Width           =   1095
  117.    End
  118.    Begin VB.Label Label4 
  119.       Caption         =   "Service &Type:"
  120.       Height          =   255
  121.       Left            =   120
  122.       TabIndex        =   6
  123.       Top             =   1560
  124.       Width           =   1215
  125.    End
  126.    Begin VB.Label Label3 
  127.       Caption         =   "&File Name:"
  128.       Height          =   255
  129.       Left            =   120
  130.       TabIndex        =   4
  131.       Top             =   1080
  132.       Width           =   1215
  133.    End
  134.    Begin VB.Label Label2 
  135.       Caption         =   "&Display Name:"
  136.       Height          =   255
  137.       Left            =   120
  138.       TabIndex        =   2
  139.       Top             =   600
  140.       Width           =   1215
  141.    End
  142.    Begin VB.Label Label1 
  143.       Caption         =   "&Service Name:"
  144.       Height          =   255
  145.       Left            =   120
  146.       TabIndex        =   0
  147.       Top             =   120
  148.       Width           =   1095
  149.    End
  150. Attribute VB_Name = "frmConfigure"
  151. Attribute VB_GlobalNameSpace = False
  152. Attribute VB_Creatable = False
  153. Attribute VB_PredeclaredId = True
  154. Attribute VB_Exposed = False
  155. '****************************************************************************************************
  156. '   Copyright (c) Key Technology Pty Ltd 1999, All Rights Reserved.
  157. '   Web site: http://www.keytech.com.au  Email: info@keytech.com.au
  158. '****************************************************************************************************
  159. Option Explicit
  160. Private mServiceName As String
  161. Private mConfigurationChanged As Boolean
  162. Private Sub FillDependenciesListView()
  163.     On Error GoTo ErrorHandler
  164.     ' Clear the list view
  165.     listDependencies.ListItems.Clear
  166.     ' Open the service manager
  167.     Dim ServiceManager As New ServiceManager
  168.     ServiceManager.ComputerName = frmMain.ComputerName
  169.     ' Check if any services!
  170.     Dim v As Variant
  171.     v = ServiceManager.Services
  172.     If VarType(v) <> (vbString Or vbArray) Then Exit Sub
  173.     ' Display the service names
  174.     Dim ServiceName() As String
  175.     Dim i As Integer
  176.     Dim ListItem As ListItem
  177.     Dim Text As String
  178.     ServiceName = v
  179.     For i = LBound(ServiceName) To UBound(ServiceName)
  180.         ' Exclude the service being configured
  181.         If ServiceName(i) <> mServiceName Then
  182.             ' Service display name
  183.             Dim DisplayName As String
  184.             
  185.             DisplayName = ServiceManager.DisplayName(ServiceName(i))
  186.             
  187.             Set ListItem = listDependencies.ListItems.Add(, ServiceName(i), DisplayName)
  188.         End If
  189.     Next
  190.     Exit Sub
  191. ErrorHandler:
  192.     MsgBox Err.Description, vbExclamation
  193. End Sub
  194. Private Sub SetDependenciesStatus()
  195.     On Error GoTo ErrorHandler
  196.     ' Get the configuration object for the selected service
  197.     Dim ServiceManager As New ServiceManager
  198.     Dim ServiceConfiguration As ServiceConfiguration
  199.     ServiceManager.ComputerName = frmMain.ComputerName
  200.     Set ServiceConfiguration = ServiceManager.Configuration(mServiceName)
  201.         
  202.     ' Display dependencies
  203.     Dim v As Variant
  204.     Dim i As Integer
  205.     Dim DependencyName() As String
  206.     Dim DependencyCount As Long
  207.     Dim ListItem As ListItem
  208.     v = ServiceConfiguration.Dependencies
  209.     If VarType(v) <> (vbString Or vbArray) Then Exit Sub
  210.     DependencyName = v
  211.     DependencyCount = UBound(DependencyName) - LBound(DependencyName) + 1
  212.     For i = LBound(DependencyName) To UBound(DependencyName)
  213.         On Error Resume Next
  214.         Set ListItem = listDependencies.ListItems(DependencyName(i))
  215.         On Error GoTo 0
  216.         
  217.         If Not ListItem Is Nothing Then ListItem.Checked = True
  218.     Next
  219.     Exit Sub
  220. ErrorHandler:
  221.     MsgBox Err.Description, vbExclamation
  222. End Sub
  223. Private Sub cmdCancel_Click()
  224.     Unload Me
  225. End Sub
  226. Private Sub cmdOK_Click()
  227.     On Error GoTo ErrorHandler
  228.     Dim ServiceManager As New ServiceManager
  229.     ServiceManager.ComputerName = frmMain.ComputerName
  230.     ServiceManager.AccessMode = WriteAccess
  231.     ' If a new service, create it
  232.     If Len(mServiceName) = 0 Then
  233.         ServiceManager.Create txtServiceName, txtDisplayName, txtFileName
  234.         mServiceName = txtServiceName
  235.     End If
  236.     ' Get the configuration object for the selected service
  237.     Dim ServiceConfiguration As ServiceConfiguration
  238.     Set ServiceConfiguration = ServiceManager.Configuration(mServiceName)
  239.     ' Set the display name
  240.     ServiceConfiguration.DisplayName = txtDisplayName
  241.     ' Set the file name
  242.     ServiceConfiguration.FileName = txtFileName
  243.     ' Set the service type
  244.     Dim ServiceType As ServiceType
  245.     Select Case cboServiceType.ListIndex
  246.         Case 0
  247.             ServiceType = Win32OwnProcess
  248.             
  249.         Case 1
  250.             ServiceType = Win32OwnProcess Or InteractiveProcess
  251.             
  252.         Case 2
  253.             ServiceType = Win32ShareProcess
  254.             
  255.         Case 3
  256.             ServiceType = Win32ShareProcess Or InteractiveProcess
  257.     End Select
  258.     ServiceConfiguration.ServiceType = ServiceType
  259.     ' Set the error control
  260.     Dim ErrorControl As ErrorControl
  261.     Select Case cboErrorControl.ListIndex
  262.         Case 0
  263.             ErrorControl = Ignore
  264.             
  265.         Case 1
  266.             ErrorControl = Normal
  267.         
  268.         Case 2
  269.             ErrorControl = Severe
  270.         
  271.         Case 3
  272.             ErrorControl = Critical
  273.     End Select
  274.     ServiceConfiguration.ErrorControl = ErrorControl
  275.     ' Set the dependencies
  276.     Dim v As Variant
  277.     Dim DependencyName() As String
  278.     Dim DependencyCount As Long
  279.     Dim ListItem As ListItem
  280.     For Each ListItem In listDependencies.ListItems
  281.         If ListItem.Checked Then
  282.             DependencyCount = DependencyCount + 1
  283.             ReDim Preserve DependencyName(1 To DependencyCount) As String
  284.             DependencyName(DependencyCount) = ListItem.Key
  285.         End If
  286.     Next
  287.     If DependencyCount Then v = DependencyName
  288.     ServiceConfiguration.Dependencies = v
  289.     mConfigurationChanged = True
  290.     Unload Me
  291.     Exit Sub
  292. ErrorHandler:
  293.     MsgBox Err.Description, vbExclamation
  294. End Sub
  295. Private Sub Form_Load()
  296.     On Error GoTo ErrorHandler
  297.     ' Display service name
  298.     txtServiceName = mServiceName
  299.     ' Fill the dependencies list view
  300.     FillDependenciesListView
  301.     ' If creating a service nothing more to display
  302.     If Len(mServiceName) = 0 Then
  303.         Caption = "Create Service"
  304.         cboServiceType.ListIndex = 0
  305.         cboErrorControl.ListIndex = 1
  306.         Exit Sub
  307.     End If
  308.     Caption = "Configure Service"
  309.     txtServiceName.Locked = True
  310.     ' Get the configuration object for the selected service
  311.     Dim ServiceManager As New ServiceManager
  312.     Dim ServiceConfiguration As ServiceConfiguration
  313.     ServiceManager.ComputerName = frmMain.ComputerName
  314.     Set ServiceConfiguration = ServiceManager.Configuration(mServiceName)
  315.     ' Display display name
  316.     txtDisplayName = ServiceConfiguration.DisplayName
  317.     ' Display file name
  318.     txtFileName = ServiceConfiguration.FileName
  319.     ' Display service type
  320.     Select Case ServiceConfiguration.ServiceType
  321.         Case Win32OwnProcess
  322.             cboServiceType.ListIndex = 0
  323.             
  324.         Case Win32OwnProcess Or InteractiveProcess
  325.             cboServiceType.ListIndex = 1
  326.             
  327.         Case Win32ShareProcess
  328.             cboServiceType.ListIndex = 2
  329.         
  330.         Case Win32ShareProcess Or InteractiveProcess
  331.             cboServiceType.ListIndex = 3
  332.             
  333.         Case Else
  334.             cboServiceType.ListIndex = 0
  335.     End Select
  336.     ' Display error control
  337.     Select Case ServiceConfiguration.ErrorControl
  338.         Case Ignore
  339.             cboErrorControl.ListIndex = 0
  340.             
  341.         Case Normal
  342.             cboErrorControl.ListIndex = 1
  343.         
  344.         Case Severe
  345.             cboErrorControl.ListIndex = 2
  346.         
  347.         Case Critical
  348.             cboErrorControl.ListIndex = 3
  349.         
  350.         Case Else
  351.             cboErrorControl.ListIndex = 0
  352.     End Select
  353.     ' Display dependencies
  354.     SetDependenciesStatus
  355.     Exit Sub
  356. ErrorHandler:
  357.     MsgBox Err.Description, vbExclamation
  358. End Sub
  359. Public Property Let ServiceName(ByVal NewValue As String)
  360.     mServiceName = NewValue
  361. End Property
  362. Public Property Get ConfigurationChanged() As Boolean
  363.     ConfigurationChanged = mConfigurationChanged
  364. End Property
  365.